<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="基地名称" prop="ebBaseName">
        <el-input
          v-model="queryParams.ebBaseName"
          placeholder="请输入基地名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌" prop="ebBrand">
        <el-input
          v-model="queryParams.ebBrand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="data" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="基地名称" align="center" prop="ebBaseName" />
      <el-table-column label="所在省" align="center" prop="province" />
      <el-table-column label="所在市" align="center" prop="city" />
      <el-table-column label="状态" align="center" prop="ebStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.base_status" :value="scope.row.ebStatus"/>
        </template>

      </el-table-column>
      <el-table-column label="投产日期" align="center" prop="ebProductionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ebProductionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="建厂形式" align="center" prop="ebFactoryType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.factory_type" :value="scope.row.ebFactoryType"/>
        </template>
      </el-table-column>
      <el-table-column label="生产线(条)" align="center" prop="ebProductionLine" />
      <el-table-column label="审核状态" align="center" prop="ebState" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.ebState === '0'" type="info">待审核</el-tag>
          <el-tag v-if="scope.row.ebState === '1'" type="error">不合格</el-tag>
          <el-tag v-if="scope.row.ebState === '2'" >正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-check"
            @click="handleAuditing(scope.row)"
            v-hasPermi="['info:base:auditing']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['info:base:auditingDetail']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import ListMixin from "@/minixs/list"
import request from "@/utils/request";
export default {
  name: "list",
  mixins:[ListMixin],
  dicts:['base_status','factory_type'],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ebName: null,
        ebBaseName: null,
        ebAddress: null,
        ebStatus: null,
        ebProductionDate: null,
        ebFactoryType: null,
        ebProductionLine: null,
        ebFixedCapacity: null,
        ebMaxCapacity: null,
        ebInventory: null,
        ebBrand: null,
        ebForm: null,
        ebCurrentCapacity: null,
        ebNextRoadmap: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**
     * 查看详情
     */
    handleDetail(row){
      const id = row.id || this.ids[0]
      this.$emit("detail-handle", {
        id:id,
        open: true,
        title: "详情"+this.title,
        type:'DETAIL'
      })
    },
    handleAuditing(row){
      const id = row.id || this.ids[0]
      this.$emit("auditing-handle", {
        id:id,
        open: true,
        title: "详情"+this.title,
        type:'AUDITING'
      })
    },
    /** 查询企业基地列表 */
    getList() {
      this.loading = true;
      request({
        url: '/info/base/auditing/list',
        method: 'get',
        params: this.queryParams
      }).then(response => {

        this.data = response.rows.map(item=>{
          const citys = item.ebCity.split(",")
          if(citys.length >= 2){
            item.province = citys[0]
            item.city = citys[1]
          }
          return item;
        });
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('/info/base/export', {
        ...this.queryParams
      }, `base_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
